package xian.woniuxy.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xian.woniuxy.dao.GoodsMapper;
import xian.woniuxy.entity.Goods;
import xian.woniuxy.service.IGoodsService;
import xian.woniuxy.util.Pageable;

import java.util.List;

/**
 * @author Zhuloong
 * @time 2021/12/26 13:38:58
// */
@Service
@Transactional
public class GoodsServiceImpl implements IGoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override

    public void delete(int goods_id) {
        goodsMapper.delete(goods_id);
    }

    @Override
    public void update(Goods goods) {
        goodsMapper.update(goods);
    }
    @Override
    public List<Goods> findAll() {
        return goodsMapper.findAll();
    }

    @Override
    public List<Goods> findFromName(String name) {
        return goodsMapper.findFromName(name);
    }
    @Override
    public Pageable findAll(int page, int size) {
        List<Goods> all = goodsMapper.findAll(page, size);

        int count = goodsMapper.Count();

        int pageCount = count / size + (count % size != 0 ? 1 : 0);

        Pageable pageable = new Pageable(pageCount, count,  all, size, page);


        return pageable;
    }
    @Override
    public void save(Goods goods) {
        goodsMapper.save(goods);
    }
    
}
